
#include "component.h"
#include "composite.h"
#include <vector>
#include <iostream>

void Composite::Add(Component *com)
{
    com_list_.push_back(com);
}

void Composite::Remove(Component *com)
{
    for (auto it = com_list_.begin(); it != com_list_.end(); it++)
    {
        if (*it == com) 
        {
            com_list_.erase(it);
            break;
        }
    }
}

Component *Composite::Get(int idx)
{
    return com_list_[idx];
}

void Composite::Operation()
{
    std::cout << "-" << name_;
    for (auto com : com_list_)
    {
        com->Operation();
    }
}

